/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;


/**
 *
 * @author milokokok
 */
 
 
@Entity
@Table(name="products" , catalog="", schema="")
@NamedQueries({
    @NamedQuery(name="Products.getProductsByType", query = "SELECT p FROM products p WHERE p.id_products = :id_products")
})
public class Products extends BaseEntity implements Serializable {
    
private static final long serialVersionUID = 1L;

/*    private double  price;
 private String description;*/
    
    @Column(name="description")
    private String description;
    @Column(name="name", nullable=false)
    private String name;
    @Column(name="price", nullable=false)
    private double price;
    @Column(name="unit", nullable=false, length=255)
    private String unit;
    @Column(name="productType",nullable=false)
    private ProductType productType;

    @OneToMany(mappedBy="id_products")
    private List<Comments> listComments;
    private String type;
     

    
    
    public Products() {
    }
    
    public Products(Long id) {
        this.id = id;
    } 
    
    public Products (String name, String description, double  price, String unit, ProductType productType) {
        this.name = name;
        this.description = description;
        this.price = price;
        this.unit = unit;
        this.productType = productType;
              
        
    }
    
    
    
    
    
public ProductType getproductType() {
        return productType;
    }

    public void setProductType (ProductType productType) {
        this.productType = productType;
    }
    
    

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
      
    
     public List<Comments> getListComments() {
        return listComments;
    }

    public void setListComments(List<Comments> listComments) {
        this.listComments = listComments;
    }

    
    
    public void addComment(Comments comment) {
        if (null == comment) return;
        if (null == this.listComments) {
            this.listComments = new ArrayList<Comments>() {};
        }
        this.listComments.add(comment);
    }
         
    public boolean deleteComment(Comments comment) {
        if (null != this.listComments && null != comment) {
            return listComments.remove(comment);
        } else {
            return false;
        }
    }
    
    

    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Users)) {
            return false;
        }
        Users other = (Users) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "models.Users[ id=" + id + " ]";
    }
    
}